package com.newlink.building.userinfo.activity

import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.newlink.building.common_base.base.NL_BaseMvpActivity
import com.newlink.building.common_base.ext.showToast
import com.newlink.building.common_base.model.bean.FamilyManagementListData1
import com.newlink.building.common_base.widget.CustomDialog
import com.newlink.building.userinfo.R
import com.newlink.building.userinfo.databinding.ActivityFamilyManagementDetailWaitActivationEmailBinding
import com.newlink.building.userinfo.mvp.Module_UserInfo_FamilyManagementDetailWaitActivationEmailPresenter
import com.newlink.building.userinfo.mvp.contract.Module_UserInfo_FamilyManagementDetailWaitActivationEmailContract

/**
 * @author wangyang
 * @date 2022/10/12
 * @description 我的——家庭管理——等待激活状态的详情页（邮箱）页面
 */
class Module_UserInfo_FamilyManagementDetailWaitActivationEmailActivityNL :
    NL_BaseMvpActivity<Module_UserInfo_FamilyManagementDetailWaitActivationEmailContract.View, Module_UserInfo_FamilyManagementDetailWaitActivationEmailContract.Presenter>(),
    Module_UserInfo_FamilyManagementDetailWaitActivationEmailContract.View, View.OnClickListener {

    var data: FamilyManagementListData1? = null

    companion object {
        /**
         * 对外开放统一入口
         *
         * @param context
         * @param url     name
         * @param title   phone
         */
        fun startSelf(context: Context?, data: FamilyManagementListData1) {
            val intent =
                Intent(context, Module_UserInfo_FamilyManagementDetailWaitActivationEmailActivityNL::class.java)
            intent.putExtra("data", data)
            context?.startActivity(intent)
        }
    }

//    override fun attachLayoutRes(): Int =
//        R.layout.activity_family_management_detail_wait_activation_email

    private lateinit var mBinding: ActivityFamilyManagementDetailWaitActivationEmailBinding
    override fun attachLayoutRes(): View {
        mBinding = ActivityFamilyManagementDetailWaitActivationEmailBinding.inflate(layoutInflater)
        return mBinding.root
    }

    override fun initData() {
        data = intent?.getSerializableExtra("data") as FamilyManagementListData1?
    }

    override fun initView() {
        super.initView()
        findViewById<TextView>(R.id.tv_title_bar_center).text =
            resources.getText(R.string.family_management_detail_title)
        findViewById<ImageView>(R.id.iv_title_bar_right).setBackgroundResource(R.mipmap.title_bar_delete)
        if (isPrimaryAccount) {
            findViewById<ImageView>(R.id.iv_title_bar_right).visibility = View.VISIBLE
        } else {
            findViewById<ImageView>(R.id.iv_title_bar_right).visibility = View.GONE
        }
        findViewById<ImageView>(R.id.iv_title_bar_right).setOnClickListener(this)

//        Glide
//            .with(this)
//            .load(data?.picture)
//            .transform(MultiTransformation(CenterCrop(), CircleCrop()))
//            .placeholder(R.mipmap.family_management_head)
//            .into(iv_head)
        mBinding.tvName.text = data?.name
        mBinding.tvPhone.text = data?.aid.toString()
        mBinding.tvPhone.visibility = View.GONE
        mBinding.rlEmail.visibility = View.GONE
//        if (TextUtils.isEmpty(data?.email)) {
//            mBinding.rlEmail.visibility = View.GONE
//        } else {
//            mBinding.rlEmail.visibility = View.VISIBLE
//            mBinding.tvEmail.text = data?.email
//        }
        mBinding.btnSendEmail.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.iv_title_bar_right -> {
                //删除
                CustomDialog(this).setMessage(getString(R.string.family_management_delete))
                    .setPositiveButton(object : CustomDialog.OnClickListener {
                        override fun onClick(dialog: CustomDialog) {
                            data?.id?.let {
//                                if (serverType == 0) {
                                mPresenter?.deleteFamilyManagement(accessToken, "$it")
//                                }else{
//                                    mPresenter?.deleteFamilyManagementFromKcp(accessToken, "$userId" , "$it" )
//                                }
                            }
                            dialog.dismiss()
                        }
                    }).setNegativeButton(object : CustomDialog.OnClickListener {
                        override fun onClick(dialog: CustomDialog) {
                            dialog.dismiss()
                        }
                    }).show()
            }

            R.id.btn_send_email -> {
                //发邮件提醒
            }
        }
    }

    override fun createPresenter(): Module_UserInfo_FamilyManagementDetailWaitActivationEmailContract.Presenter =
        Module_UserInfo_FamilyManagementDetailWaitActivationEmailPresenter()

    override fun deleteFamilyManagementSuccess() {
        showToast(getString(R.string.default_delete_success))
        finish()
    }

    override fun deleteFamilyManagementFail() {
        showToast(getString(R.string.default_delete_fail))
    }
}